<template>
  <el-dialog
    title="选择冷库设备"
    :visible.sync="innerVisible"
    width="1000px"
    @close="handleClose"
  >
    <el-table
      :data="deviceList"
      style="width: 100%"
    >
      <el-table-column type="index" label="#" width="50" align="center"></el-table-column>
      <el-table-column prop="deviceNumber" label="设备编号" align="center"></el-table-column>
      <el-table-column prop="deviceName" label="设备名称" align="center"></el-table-column>
      <el-table-column label="操作" width="100" align="center">
        <template slot-scope="{ row }">
          <el-button type="text" size="mini" @click="selectDevice(row)">
            选中
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
</template>

<script>
export default {
  name: "deviceSelect",
  props: {
    visible: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      innerVisible: this.visible,
      deviceList: [
        {deviceNumber: 'DEV-001', deviceName: '蔬菜冷藏库'},
        {deviceNumber: 'DEV-002', deviceName: '果蔬冷藏库'},
        {deviceNumber: 'DEV-003', deviceName: '肉禽冷冻库'}
      ]
    }
  },
  watch: {
    visible(val) {
      this.innerVisible = val
    },
    innerVisible(val) {
      this.$emit('update:visible', val)
    }
  },
  methods: {
    selectDevice(row) {
      this.$emit('select', row)
      this.innerVisible = false
    },
    handleClose() {
      this.innerVisible = false
    }
  }
}
</script>

<style scoped>

</style>
